<?php
global $bp;

$category = esc_attr__( bp_current_action() );
$all_achievements = dpa_get( '*', array( array( 'type' => 'd', 'key' => 'active', 'value' => 1 ), array( 'type' => 's', 'key' => 'category', 'value' => $category ) ) );

if ( bp_is_home() )
	$user_id = $bp->loggedin_user->id;
else
	$user_id = $bp->displayed_user->id;

$earnt = (int) dpa_get_count_of_ea( $user_id, $category );
$active = (int) dpa_get( 'COUNT(short_name)', array( array( 'type' => 'd', 'key' => 'active', 'value' => 1 ), array( 'type' => 's', 'key' => 'category', 'value' => $category ) ) );
$percentage = ($earnt / $active) * 100;

$class = 'bar';
if ( $percentage < 100 )
	$class .= ' flatright';

get_header();
?>

<div class="content-header"></div>

<div id="content">
	<?php do_action( 'template_notices' ); ?>

	<div id="dpa">
		<div id="dpa-graphs">
			<div class="graph fullsize">
				<div class="<?php echo $class; ?>" style="width: <?php echo $percentage; ?>%"></div>
				<div class="caption"><p>Total Completed: <?php echo $earnt; ?> / <?php echo $active; ?></p></div>
			</div>
		</div>

	<ul id="dpa-categorylist">
		<?php foreach ( (array) $all_achievements as $achievement ) {
			dpa_detailview( $user_id, $achievement );
		} ?>
	</ul>
</div>

<?php get_footer() ?>